package com.example.jetpackcomposestate.examples

import android.provider.CalendarContract.Colors
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 6/5/2024 下午10:56 周一
 * @description
 *
 * https://www.bilibili.com/video/BV1ob4y1a7ad?p=46&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
 */


data class Elevations(val card: Dp = 0.dp)

// 使用 compositionLocalOf 自定义一个 CompositionLocal
val LocalElevations = compositionLocalOf {
    Elevations()
}

object CardElevation {
    val high: Elevations
        get() = Elevations(card = 10.dp)

    val low: Elevations
        get() = Elevations(card = 5.dp)
}

@Composable
fun MyCard(
    elevation: Dp = LocalElevations.current.card,
    backgroundColor: Color,
    content: @Composable ColumnScope.() -> Unit
) {
    Card(
        elevation = CardDefaults.cardElevation(
            defaultElevation = elevation,
            pressedElevation = elevation,
            focusedElevation = elevation,
            hoveredElevation = elevation,
            draggedElevation = elevation,
            disabledElevation = elevation
        ),
        modifier = Modifier.size(200.dp),
        colors = CardDefaults.cardColors(
            containerColor = backgroundColor,
            disabledContainerColor = backgroundColor,
        ),
        content = content
    )
}